/*
 * @Description: 话题卡片
 * @Author: iamsmiling
 * @Date: 2021-05-24 11:59:51
 * @LastEditTime: 2021-06-13 17:22:50
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/image/chimera_image.dart';
import 'package:credit_business_circle/domain/local/topic/topic_entity.dart';
import 'package:credit_business_circle/routes/app_routes.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TopicCard extends StatelessWidget {
  final TopicEntity topic;
  final Color borderColor;
  final EdgeInsets margin;
  final bool bannerVisible;
  final WidgetBuilder? bottomRightBuilder;
  const TopicCard(
      {Key? key,
      required this.topic,
      this.borderColor = const Color(0xFFDDDDDD),
      this.margin = const EdgeInsets.symmetric(vertical: 11),
      this.bannerVisible = true,
      this.bottomRightBuilder})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => Get.toNamed(AppRoutes.topicDetail),
      child: Stack(
        children: [
          Container(
            decoration: BoxDecoration(
                color: R.color.ffffffff,
                border: Border.all(color: borderColor),
                borderRadius: BorderRadius.circular(R.dimen.sp8)),
            margin: margin,
            padding: EdgeInsets.only(
                left: R.dimen.dp10,
                right: R.dimen.dp12,
                bottom: R.dimen.dp14,
                top: R.dimen.dp10),
            child: Column(
              children: [
                Row(
                  children: [
                    ChimeraImage(
                      src: topic.userAvatar,
                      width: R.dimen.dp24,
                      height: R.dimen.dp24,
                      borderRadius: BorderRadius.circular(R.dimen.dp24 / 2),
                    ),
                    Container(
                      margin: EdgeInsets.only(
                          left: R.dimen.dp9, right: R.dimen.dp13),
                      child: Text(
                        "${topic.nickname} / ${topic.position}",
                        style: TextStyle(
                            fontSize: R.dimen.sp12, color: R.color.ff666666),
                      ),
                    ),
                    Image.asset(topic.vipLevel.icon),
                    Container(
                      margin: EdgeInsets.only(left: R.dimen.dp7),
                      child: Image.asset(R.image.jobTag),
                    ),
                  ],
                ),
                Container(
                  margin:
                      EdgeInsets.only(top: R.dimen.dp10, bottom: R.dimen.dp19),
                  child: Text.rich(TextSpan(
                      text: topic.title,
                      style: TextStyle(
                          fontSize: R.dimen.sp15,
                          color: topic.titleColor,
                          fontWeight: FontWeight.w600),
                      children: [
                        WidgetSpan(
                            child: Container(
                          child: Image.asset(R.image.imgTag),
                        ))
                      ])),
                ),
                Row(
                  children: [
                    for (TopicTagEntity tag in topic.tags)
                      Container(
                        padding: EdgeInsets.symmetric(
                            vertical: R.dimen.dp4, horizontal: R.dimen.dp6),
                        decoration: BoxDecoration(
                            color: tag.color,
                            borderRadius: BorderRadius.circular(R.dimen.sp3)),
                        margin: EdgeInsets.only(right: R.dimen.dp9),
                        child: Text(
                          tag.text,
                          style: TextStyle(
                              fontSize: R.dimen.sp11, color: R.color.ff666666),
                        ),
                      ),
                    Spacer(),
                    bottomRightBuilder != null
                        ? Builder(builder: bottomRightBuilder!)
                        : Row(
                            children: [
                              Container(
                                  margin: EdgeInsets.only(right: R.dimen.dp6),
                                  child: Image.asset(R.image.viewCount)),
                              Container(
                                margin: EdgeInsets.only(right: R.dimen.dp14),
                                child: Text(
                                  "${topic.viewCount}",
                                  style: TextStyle(
                                      color: R.color.ff555555,
                                      fontSize: R.dimen.sp11),
                                ),
                              ),
                              Container(
                                  margin: EdgeInsets.only(right: R.dimen.dp6),
                                  child: Image.asset(R.image.transactionCount)),
                              Text(
                                "${topic.transactionCount}",
                                style: TextStyle(
                                    color: R.color.ff555555,
                                    fontSize: R.dimen.sp11),
                              )
                            ],
                          )
                  ],
                )
              ],
            ),
          ),
          Positioned(
              top: R.dimen.dp11,
              right: 0,
              child: Visibility(
                visible: bannerVisible,
                child: Container(
                  padding: EdgeInsets.symmetric(
                      horizontal: R.dimen.dp10, vertical: R.dimen.dp2),
                  decoration: BoxDecoration(
                      color: topic.bannerColor,
                      borderRadius: BorderRadius.only(
                        topRight: Radius.circular(R.dimen.sp8),
                        bottomLeft: Radius.circular(R.dimen.sp8),
                      )),
                  child: Text(
                    "${topic.bannerLabel}",
                    style: TextStyle(
                        color: R.color.fff5f5f5, fontSize: R.dimen.sp11),
                  ),
                ),
              )),
          Positioned(
              bottom: R.dimen.dp36 + R.dimen.dp14,
              right: R.dimen.dp56 - R.dimen.dp12,
              child: Image.asset(R.image.contacted))
        ],
      ),
    );
  }
}
